<?php

namespace App\Resource\Admin;

use App\Model\SystemLog;
use Hyperf\Resource\Json\JsonResource;

/**
 * @mixin SystemLog
 */
class SystemLogResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array
     */
    public function toArray(): array
    {
        return [
            'id' => $this->id,
            'user_id' => $this->user_id,
            'action' => $this->action,
            'description' => $this->description,
            'ip_address' => $this->ip_address,
            'user_agent' => $this->user_agent,
            'request_data' => $this->request_data,
            'response_data' => $this->response_data,
            'created_at' => $this->created_at->format('Y-m-d H:i:s'),
            'user' => $this->whenLoaded('user', fn () => $this->user),
        ];
    }
}
